package teacher.service;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import database.dao.MysqlCrud;
import teacher.bean.Award;
import teacher.bean.Flow;
import teacher.bean.Paper;
import teacher.bean.Patent;
import teacher.bean.Project;
import teacher.bean.Teacher;
import teacher.bean.Treatise;
import teacher.page.Page;
import beanDao.MapToBean;

public class flow {
	/**
	 * @category 插入一条流程管理数据
	 */
	public boolean insertFlow(Flow flow){
		boolean flag = false;
		String sql="insert into flow(fruitId,dirDo,subDo,fruitKind,teaDo,teaTime,dirTime,subTime)"+"values(?,?,?,?,?,?,?,?)";
		String[] parameter={
				String.valueOf(flow.getFruitId()),
				String.valueOf(flow.getDirDo()),
				String.valueOf(flow.getSubDo()),
				String.valueOf(flow.getFruitKind()),
				String.valueOf(flow.getTeaDo()),
				String.valueOf(flow.getTeaTime()),
				String.valueOf(flow.getDirTime()),
				String.valueOf(flow.getSubTime())
		};
		MysqlCrud mysqlcurd=new MysqlCrud();
		flag = mysqlcurd.InsertAndUpdateData(sql, parameter);
		return flag;
	}
	
	/**
	 * @category 删除一条flow数据
	 */
	public boolean DeleteFlow(int id,int kind){
		String sql = "delete from flow where fruitId="+id+" and fruitKind="+kind+"";
		 MysqlCrud mysqlcurd=new MysqlCrud();
		 boolean flag= mysqlcurd.InsertAndUpdateData(sql, null);
		 return flag;
	}
	
	/**
	 * @category 通过获奖名查询一项论文
	 */
	public Paper selectPaperByName(String name) {
		Paper paperTwo = new Paper();
		String sql= "select * from paper where name like '%"+name+"%'";
		int i=0;	
		MysqlCrud mysqlcurd=new MysqlCrud();
		List<Map> list = mysqlcurd.SelectData(sql, null);
		//System.out.println(list.size());
		if(1==list.size()){
			Map map=list.get(0);
			paperTwo=new MapToBean().MapToPaper(map);
		}
		return paperTwo;
	}
	
	/**
	 * @category 通过获奖名查询一项专利
	 */
	public Patent selectPatentByName(String name) {
		Patent p = new Patent();
		String sql= "select * from patent where name like '%"+name+"%'";
		int i=0;	
		MysqlCrud mysqlcurd=new MysqlCrud();
		List<Map> list = mysqlcurd.SelectData(sql, null);
		//System.out.println(list.size());
		if(1==list.size()){
			Map map=list.get(0);
			p=new MapToBean().MapToPatent(map);
		}
		return p;
	}
	
	/**
	 * @category 通过获奖名查询一项项目
	 */
	public Project selectProjectByName(String name) {
		Project p = new Project();
		String sql= "select * from project where name like '%"+name+"%'";
		int i=0;	
		MysqlCrud mysqlcurd=new MysqlCrud();
		List<Map> list = mysqlcurd.SelectData(sql, null);
		//System.out.println(list.size());
		if(1==list.size()){
			Map map=list.get(0);
			p=new MapToBean().MapToProject(map);
		}
		return p;
	}
	
	/**
	 * @category 通过获奖名查询一项论著
	 */
	public Treatise selectTreatiseByName(String name) {
		Treatise t1 = new Treatise();
		String sql= "select * from treatise where name like '%"+name+"%'";
		int i=0;	
		MysqlCrud mysqlcurd=new MysqlCrud();
		List<Map> list = mysqlcurd.SelectData(sql, null);
		//System.out.println(list.size());
		if(1==list.size()){
			Map map=list.get(0);
			t1=new MapToBean().MapToTreatise(map);
		}
		return t1;
	}
	
	/**
	 * @category 通过获奖名查询一项获奖
	 */
	public Award selectAwardByName(String name) {
		Award a = new Award();
		String sql= "select * from award where name like '%"+name+"%'";
		int i=0;	
		MysqlCrud mysqlcurd=new MysqlCrud();
		List<Map> list = mysqlcurd.SelectData(sql, null);
		//System.out.println(list.size());
		if(1==list.size()){
			Map map=list.get(0);
			a=new MapToBean().MapToAward(map);
		}
		return a;
	}
	
	/**
	 * @category 通过Id跟Kind查询一条flow
	 */
	public List<Flow> selectFlowById(int id,int kind) {
		String sql= "select * from flow where fruitId="+id+" and fruitKind="+kind+"";
		int i=0;
		List<Flow> flow1=new ArrayList<Flow>();
		MysqlCrud mysqlcurd=new MysqlCrud();
		List<Map> list = mysqlcurd.SelectDataInt(sql, null);
		while(i<list.size()){
			Map map=list.get(i);
			try {
				Flow f = new Flow();
				f.setFlowId(Integer.parseInt(map.get(0).toString()));
				f.setFruitId(Integer.parseInt(map.get(1).toString()));
				f.setDirDo(Integer.parseInt(map.get(2).toString()));
				f.setSubDo(Integer.parseInt(map.get(3).toString()));
				f.setFruitKind(Integer.parseInt(map.get(4).toString()));
				f.setTeaDo(Integer.parseInt(map.get(5).toString()));
				f.setTeaTime(map.get(6).toString());
				f.setDirTime(map.get(7).toString());
				f.setSubTime(map.get(8).toString());		
				flow1.add(f);
			} catch (Exception e) {
				// TODO: handle exception
				e.printStackTrace();
			}
			i++;
		}
		return flow1;
	}
	
}
